<%@page import="java.util.List"%>
<%@page import="shoppingmall.jmu.cart.entity.Cart"%>
<%@page import="shoppingmall.jmu.cart.dao.impl.CartDAOImpl"%>
<%@page import="shoppingmall.jmu.cart.dao.CartDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String user_id = request.getParameter("user_id");
	String product = request.getParameter("product");
	String c = request.getParameter("count");
	
	int count = Integer.parseInt(c);
	int result = 0;
	boolean flag = false;
	
	CartDAO cd = new CartDAOImpl();
	List<Cart> clist = cd.getAllCartById(user_id);
	for(Cart cart : clist){
		if(cart.getProduct().equals(product)){
			result = cd.updateCert(user_id, product, count);
			flag = true;
			break;
		}
	}
	if(!flag)
		result = cd.addIntoCert(user_id, product, count);
	
	response.sendRedirect("cart.jsp");
	
%>